from qiniu import Auth, put_data

# 需要填写你的 Access Key 和 Secret Key
access_key = "ucdfyhFCOS-VioxqcSkAZe83RwjWyPGFPXL1CIQP"
secret_key = "N2-i6t4uROO9seucyKwQpTy3XcxPoVumtoE6w9rS"

# 要上传的空间
bucket_name = 'niuniu777'


def storage(data):
    try:
        q = Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        ret, info = put_data(token, None, data)
        print(ret, info)
    except Exception as e:
        raise e
    if info.status_code != 200:
        raise Exception("上传图片失败")
    return ret["key"]

if __name__ == "__main__":
    file = input("请输入文件路径")
    with open(file, "rb") as f:
        storage(f.read())
